package com.ruoyi.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DeptApply;
import com.ruoyi.system.service.IDeptApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 部门Controller
 *
 * @author ruoyi
 * @date 2024-08-30
 */
@RestController
@RequestMapping("/system/deptApply")
public class DeptApplyController extends BaseController {
    @Resource
    private IDeptApplyService deptApplyService;

    /**
     * 查询部门列表
     */
    //@PreAuthorize("@ss.hasPermi('system:deptApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeptApply deptApply) {
        startPage();
        List<DeptApply> list = deptApplyService.selectDeptApplyList(deptApply);
        return getDataTable(list);
    }

    /**
     * 导出部门列表
     */
    //@PreAuthorize("@ss.hasPermi('system:deptApply:export')")
    @Log(title = "部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeptApply deptApply) {
        List<DeptApply> list = deptApplyService.selectDeptApplyList(deptApply);
        ExcelUtil<DeptApply> util = new ExcelUtil<DeptApply>(DeptApply.class);
        util.exportExcel(response, list, "部门数据");
    }

    /**
     * 获取部门详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:deptApply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(deptApplyService.selectDeptApplyById(id));
    }

    /**
     * 新增部门
     */
    /*//@PreAuthorize("@ss.hasPermi('system:deptApply:add')")
    @Log(title = "部门", businessType = BusinessType.INSERT)*/
    @PostMapping
    @Anonymous
    public AjaxResult add(@RequestBody DeptApply deptApply) {
        return toAjax(deptApplyService.insertDeptApply(deptApply));
    }

    /**
     * 修改部门
     */
    //@PreAuthorize("@ss.hasPermi('system:deptApply:edit')")
    @Log(title = "部门", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeptApply deptApply) {
        return toAjax(deptApplyService.updateDeptApply(deptApply));
    }

    /**
     * 删除部门
     */
    //@PreAuthorize("@ss.hasPermi('system:deptApply:remove')")
    @Log(title = "部门", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(deptApplyService.deleteDeptApplyByIds(ids));
    }
}
